package cn.alpha.intell.rbtlib.wifi.dlalog;

import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.alpha.intell.rbtlib.R;

/**
 * @author : jinlongfeng
 * @version : V2.1.2
 * @description: 长按已经保存的网络弹出的 dialog
 * @time : 2016/12/10-10:06
 */

public class WiFiEditChooseDialog extends Dialog {

    public WiFiEditChooseDialog(Context context) {
        super(context);
    }

    public WiFiEditChooseDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    private void applyCompat() {
        if (Build.VERSION.SDK_INT < 19) {
            return;
        }
        getWindow().setFlags(
                WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        applyCompat();
        super.onCreate(savedInstanceState);
    }

    public static class Builder {


        private Context mContext;

        private WIFIPickCallBack mCallBack;

        private String wifiSSID;


        public Builder(Context context) {
            this.mContext = context;
        }

        public Builder setCallBack(WIFIPickCallBack pickCallBack){
            this.mCallBack = pickCallBack;
            return this;
        }
        public Builder setWifiSSID(String ssid){
            this.wifiSSID = ssid;
            return this;
        }

        public WiFiEditChooseDialog create(){
            final WiFiEditChooseDialog dialog = new WiFiEditChooseDialog(mContext, R.style.Dialog);
            LayoutInflater layoutInflater = dialog.getLayoutInflater();
            View rootView = layoutInflater.inflate(R.layout.dialog_wifi_longclick,null);

            TextView textViewSSID;
            ImageView imageViewClose;
            TextView textViewDel,textViewEdit;

            textViewSSID = (TextView) rootView.findViewById(R.id.tv_wifi_ssid);
            imageViewClose = (ImageView) rootView.findViewById(R.id.iv_close);
            textViewDel = (TextView) rootView.findViewById(R.id.tv_wifi_dele);
            textViewEdit = (TextView) rootView.findViewById(R.id.tv_wifi_edit);


            textViewSSID.setText(wifiSSID);
            imageViewClose.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    dialog.dismiss();
                }
            });

            textViewDel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if(mCallBack!=null){
                        mCallBack.onDeleWiFi(wifiSSID);
                    }
                    dialog.dismiss();

                }
            });

            textViewEdit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(mCallBack!=null){
                        mCallBack.onEditWiFi(wifiSSID);
                    }
                    dialog.dismiss();
                }
            });

            dialog.addContentView(rootView, new LinearLayout.LayoutParams(758, 345));
            dialog.setCanceledOnTouchOutside(true);
            return dialog;

        }

        public interface  WIFIPickCallBack{
            void onDeleWiFi(String ssid);
            void onEditWiFi(String ssid);

        }
    }



}
